---
title: "Cleaning FES Youth Studies - East Europe and Central Asia"
---

# Load

```{r}
# load packages
  source("helper-packages.R")

# load bulgaria
  bulgaria_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/bulgaria-2014/Bulgarian youth SPSS file 2014 ENGLISH.sav")
  
# load kazakhstan
  kazakhstan_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/kazakhstan-2016-LANG-ISSUE/KazakhstanyouthSPSSfile.sav")

# load kosovo
  kosovo_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/kosovo-2012/Kosovo youth SPSS file 2012 ENGLISH .sav") 
  
# load kyrgyzstan
  kyrgyzstan_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/kyrgyzstan-2016-LANG-ISSUE/KyrgyzstanyouthSPSSfile.sav")
  
# load romania 
  romania_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/romania-2014/Romanian youth SPSS file 2014 ENGLISH.sav") 
  
# load slovenia
  slovenia_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/slovenia-2013/Slovenian youth SPSS file 2013 ENGLISH.sav")
  
# load serbia 
  serbia_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/serbia-2015/Serbian youth SPSS file.sav") 
  
# load tajikistan
  tajikistan_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/tajikistan-2016-LANG-ISSUE/TajikistanyouthSPSSfile.sav")
  
# load ukraine
  ukraine_raw <-
    read_sav("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/ukraine-2017/FES_FINAL DATABASE_ 20.09.sav")
  
# load uzbekistan
  uzbekistan_raw <-
    import("../raw-data/y-multi-fes-youth-studies/east-europe-central-asia-2011-2016/uzbekistan-2016-LANG-ISSUE/Uzbekistanyouth.csv")
```

# Clean Bulgaria

```{r}
# clean bulgaria
  clean_bulgaria <-
    bulgaria_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Bulgaria",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = NA,
    
        resp_interview_start_date = as.Date("2014-06-01"),
        resp_interview_end_date = as.Date("2014-08-01"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          dplyr::recode(
            as.character(b8),
            "1" = "Christian",
            "2" = "Muslim",
            "3" = "Other religion",
            "4" = NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          case_when(
            b8a == 1 & b8 == 1 ~ "Eastern Orthodox",
            b8a == 2 & b8 == 1 ~ "Roman Catholic",
            b8a == 3 & b8 == 1 ~ "Protestant",
            b8a == 4 & b8 == 1 ~ "Christian culture as a whole",
            b8 == 2 ~ "Muslim",
            b8 == 3 ~ "Other",
            b8 == 4 ~ NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(s5_age),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(s6a),
            "8" = "1. Lower than unfinished primary school [No education]",
            "7" = "2. Unfinished primary school [No education]",
            "6" = "3. Finished primary school [Primary]",
            "5" = "4. Unfinished secondary school [Primary]",
            "4" = "5. 3-year secondary school [Primary]",
            "3" = "6. 4-year secondary school [Primary]",
            "2" = "7. University/ Undergraduate degree [College]",
            "1" = "8. Master’s or doctoral degree [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            s4 == 1 ~ 0,
            s4 == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            s2 == 1 ~ 1,
            s2 %in% c(2:4) ~ 0),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: B1 [b1.6]; QTEXT: Where on this scale would you put the following people? Please follow the scale from 1 (trust least) to 10 (trust most). People of other religions.; ROPTIONS: 1(2/3/4/5) = Trust least [=1] + (6/7/8/9)10 = Trust most [=0]; TARGET: Different religion; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(b1_6),
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            b1_6 %in% c(1:5) ~ 1,
            b1_6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: B10.2 [b10.2]; QTEXT: How often do you pray?; ROPTIONS: 1 = Regularly + 2 = Often + 3 = Sometimes + 4 = Never",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(b10_2),
            `9` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (4 - resp_religiosity_original)/3
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Kazakhstan

```{r}
# clean kazakhstan
  clean_kazakhstan <-
    kazakhstan_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Kazakhstan",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = NA,
    
        resp_interview_start_date = as.Date("2014-12-27"),
        resp_interview_end_date = as.Date("2015-01-15"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            q23 == 1 ~ "Muslim",
            q23 %in% c(2, 3) ~ "Christian",
            q23 %in% c(5, 97, 99) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(q23),
            "1" = "Muslim",
            "2" = "Orthodox",
            "3" = "Catholic",
            "5" = NA_character_,
            "97" = NA_character_,
            "99" = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(d2),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(d4),
            "1" = "1. Elementary [Primary]",
            "2" = "2. Incomplete high school [Primary]",
            "3" = "3. Secondary [Primary]",
            "4" = "4. Vocational [Primary]",
            "5" = "5. Incomplete higher education [Primary]",
            "6" = "6. Complete higher education [College]",
            "7" = "7. Advanced education/scientific degress (doctorate) [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            d1 == 1 ~ 0,
            d1 == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            Village %in% c(100:122) ~ 1,
            City %in% c(1:16) ~ 0),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: 14 [q14.6]; QTEXT: Please tell me to what extent you trust the following people. Imagine a scale from 1 to 10, where 1 means you don't trust them completely, 10 means you trust them completely. People of other religions.; ROPTIONS: 1(2/3/4/5) = Don't trust completely [=1] + (6/7/8/9)10 = Trust completely [=0]; TARGET: Different religion; TYPE: Trust", 

      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(q14.6),
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            q14.6 %in% c(1:5) ~ 1,
            q14.6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: Q22; QTEXT: What is your attitude toward religion?; ROPTIONS: 1 = I am a believer, I am a member of a community and regularly visit a temple and a mosque, I observe rituals, prescriptions and prohibitions, I promote the values of my religion + 2 = I am a believer, but I practically do not participate in religious life, I limit myself to celebrations and some vital ceremonies + 3 = I am not a believer, but I take part in some ceremonies and holidays according to the tradition of my nationality, and I advocate my religion + 4 = I am not a believer, I do not participate in religious life, but I respect the religious feelings of believers and do not hinder them + 5 = I have my own individual belief in various values (e.g., civil religion, personal reverence for moral values, belief in a non-traditional god, etc.) + 6 = I am a non-believer, atheist, and an opponent of religion, I believe that religion does more harm to humanity than good and people need to do away with it",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(q22),
            `99` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (6 - resp_religiosity_original)/5
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Kosovo

```{r}
# clean kosovo
  clean_kosovo <-
    kosovo_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Kosovo",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = 
          make_date(
            year = INTYYYY,
            month = INTMM,
            day = INTDD),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            B8 %in% c(1, 4) ~ "Muslim",
            B8 %in% c(2, 3) ~ "Christian",
            B8 == 5 ~ "Other religion",
            B8 %in% c(6, 7 , 9) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(B8),
            "1" = "Muslim",
            "2" = "Orthodox",
            "3" = "Catholic",
            "4" = "Bektashi",
            "5" = "Other",
            "6" = NA_character_,
            "7" = NA_character_,
            "9" = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(R7),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(R8),
            "1" = "1. None [No education]",
            "2" = "2. Completed few years of lower primary education (4 years) [No education]",
            "3" = "3. Completed lower primary education [Primary]",
            "4" = "4. Completed few years of upper secondary education 7-8-9 years [Primary]",
            "5" = "5. Completed upper secondary education 7-8-9 years [Primary]",
            "6" = "6. Completed few years of secondary education [Primary]",
            "7" = "7. Completed secondary education [Primary]",
            "8" = "8. Higher education uncompleted [Primary]",
            "9" = "9. Higher education completed [Primary]",
            "10" = "10. Completed few years of university study [Primary]",
            "11" = "11. University studies completed [College]",
            "12" = "12. Grad school uncompleted [College]",
            "13" = "13. Grad school completed [College]",
            "14" = "14. PHD uncompleted [College]",
            "15" = "15. PHD completed [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            R2 == 1 ~ 0,
            R2 == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            Residential_settlement_1 == 1 ~ 0,
            Residential_settlement_1 == 2 ~ 1),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: B1 [B1.6]; QTEXT: Imagine a scale from 1 to 10 where in the first scale (1) are the people you trust less and in the last scale (the 10th) are the people you trust more. According to you, at which scale would the following people belong? People of other religions.; ROPTIONS: 1(2/3/4/5) = Trust less [=1] + (6/7/8/9)10 = Trust most [=0]; TARGET: Different religion; TYPE: Trust",
    
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(B1_6),
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            B1_6 %in% c(1:5) ~ 1,
            B1_6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: B8.1 [B8.1]; QTEXT: Using a scale from 1 to 7, where 1 means 'I practice very rarely' and 7 'regularly practice,' how often would you practice the religion to which you belong?; ROPTIONS: 1 = very rarely + (2/3/4/5/6) + 7 = regularly",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(B8_1),
            `9` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (resp_religiosity_original - 1)/6
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Kyrgyzstan

```{r}
# clean kyrgyzstan
  clean_kyrgyzstan <-
    kyrgyzstan_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Kyrgyzstan",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = NA,
    
        resp_interview_start_date = as.Date("2015-01-31"),
        resp_interview_end_date = as.Date("2015-02-11"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            q23 == 1 ~ "Muslim",
            q23 %in% c(2, 3) ~ "Christian",
            q23 %in% c(5, 97, 99) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(q23),
            "1" = "Muslim",
            "2" = "Orthodox",
            "3" = "Catholic",
            "5" = NA_character_,
            "97" = NA_character_,
            "99" = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(d2),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(d4),
            "1" = "1. Elementary [Primary]",
            "2" = "2. Incomplete high school [Primary]",
            "3" = "3. Secondary [Primary]",
            "4" = "4. Vocational [Primary]",
            "5" = "5. Incomplete higher education [Primary]",
            "6" = "6. Complete higher education [College]",
            "7" = "7. Advanced education/scientific degress (doctorate) [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            d1 == 1 ~ 0,
            d1 == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            Village %in% c(0:45) ~ 1,
            City %in% c(1:13) ~ 0),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: 14 [q14.6]; QTEXT: Please tell me to what extent you trust the following people. Imagine a scale from 1 to 10, where 1 means you don't trust them completely, 10 means you trust them completely. People of other religions.; ROPTIONS: 1(2/3/4/5) = Don't trust completely [=1] + (6/7/8/9)10 = Trust completely [=0]; TARGET: Different religion; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(q14.6),
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            q14.6 %in% c(1:5) ~ 1,
            q14.6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: Q22; QTEXT: What is your attitude toward religion?; ROPTIONS: 1 = I am a believer, I am a member of a community and regularly visit a temple and a mosque, I observe rituals, prescriptions and prohibitions, I promote the values of my religion + 2 = I am a believer, but I practically do not participate in religious life, I limit myself to celebrations and some vital ceremonies + 3 = I am not a believer, but I take part in some ceremonies and holidays according to the tradition of my nationality, and I advocate my religion + 4 = I am not a believer, I do not participate in religious life, but I respect the religious feelings of believers and do not hinder them + 5 = I have my own individual belief in various values (e.g., civil religion, personal reverence for moral values, belief in a non-traditional god, etc.) + 6 = I am a non-believer, atheist, and an opponent of religion, I believe that religion does more harm to humanity than good and people need to do away with it",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(q22),
            `7` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (6 - resp_religiosity_original)/5
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Romania

```{r}
# clean romania
  clean_romania <-
    romania_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Romania",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = NA,
    
        resp_interview_start_date = as.Date("2014-07-19"),
        resp_interview_end_date = as.Date("2014-07-31"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            b8 %in% c(1:5) ~ "Christian",
            b8 == 6 ~ "Muslim",
            b8 == 7 ~ "Other religion",
            b8 %in% c(8:9) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(b8),
            "1" = "Orthodox Christian",
            "2" = "Roman Catholic",
            "3" = "Greek Catholic",
            "4" = "Protestant",
            "5" = "Neo-Protestant",
            "6" = "Muslim",
            "7" = "Other Religion",
            "8" = NA_character_,
            "9" = NA_character_,
            .default = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(virsta),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(idiplom_re),
            "1" = "1. Maximum 4 years/grades of schooling [No education]",
            "2" = "2. General education (maximum 10 years) [Primary]",
            "3" = "3. Vocational school [Primary]",
            "4" = "4. High school [Primary]",
            "5" = "5. Post-high school (non-university) [Primary]",
            "6" = "6. University/college [College]",
            "7" = "7. Post-university (Master, PhD) [College]",
            "9" = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            sex == 1 ~ 0,
            sex == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            urbrur == 3 ~ 1,
            urbrur == 1 ~ 0),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: B1 [b1.6]; QTEXT: I will read a list to you with various groups or persons. Please tell me how much confidence you have in each group or person below, on a scale of 1 (no confidence at all) to 10 (total confidence). Persons who have another religion than you.; ROPTIONS: 1(2/3/4/5) = No confidence at all [=1] + (6/7/8/9)10 = Total confidence [=0]; TARGET: Different religion; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(b1_6),
            "666" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            b1_6 %in% c(1:5) ~ 1,
            b1_6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: B10.2 [b10.2]; QTEXT: How often do you pray?; ROPTIONS: 1 = Very often + 2 = Often + 3 = Rarely + 4 = Very rarely/never",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(b10_2),
            `9` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (4 - resp_religiosity_original)/3
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Slovenia

```{r}
# clean slovenia
  clean_slovenia <-
    slovenia_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Slovenia",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = as.Date(paste0("2013", DAT), "%Y%d%m"),

        resp_interview_start_date = as.Date("2013-05-31"),
        resp_interview_end_date = as.Date("2013-07-17"), # imputed from max and min dates to account for 20 missing dates
        
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            B8 %in% c(1, 2, 4) ~ "Christian",
            B8 == 3 ~ "Muslim",
            B8 == 5 ~ "Other religion",
            B8 == 6 ~ NA_character_,
            TRUE ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(B8),
            "1" = "Catholic",
            "2" = "Lutheran",
            "3" = "Muslim",
            "4" = "Orthodox",
            "5" = "Some other religion",
            "6" = NA_character_,
            .default = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(A0_7),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(I1_1),
            "0" = NA_character_,
            "1" = "1. Incompleted primary school [No education]",
            "2" = "2. Completed primary school [Primary]",
            "3" = "3. Completed secondary school [Primary]",
            "4" = "4. Finished short-cycle higher, non-university (college) or university education [College]",
            "5" = "5. Masters or PhD [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            A0_8 == 1 ~ 0,
            A0_8 == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural = NA,  # confirmed
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: B1 [B1.6]; QTEXT: Imagine a scale from 1 to 10 where value one (1) indicates people you trust the least, and value ten (10) indicates people you trust the most. Where do, in your opinion, the following people belong on such scale? People of different religions from your own.; ROPTIONS: 1(2/3/4/5) = Trust least [=1] + (6/7/8/9)10 = Trust most [=0]; TARGET: Different religion; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(B1_6),
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            B1_6 %in% c(1:5) ~ 1,
            B1_6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: B9; QTEXT: How important is God in your life? Please assess using a 10-point scale, where one (1) indicates 'not important at all' and ten (10) indicates 'very important.'; ROPTIONS: 1 = Not important at all + (2/3/4/5/6/7/8/9) + 10 = very important",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(B9),
            `99` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (resp_religiosity_original - 1)/9
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Serbia

```{r}
# clean serbia
  clean_serbia <-
    serbia_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Serbia",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = as.Date(datum, "%Y-%m-%d"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            VB8 %in% c(1:2) ~ "Christian",
            VB8 == 3 ~ "Muslim",
            VB8 == 5 ~ "Other religion",
            VB8 %in% c(4, 6, 88) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(VB8),
            "1" = "Christian Orthodox",
            "2" = "Christian Catholic",
            "3" = "Muslim",
            "4" = NA_character_,
            "5" = "Other",
            "6" = NA_character_,
            "88" = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(starost),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(viDIPLOM_ispitanik),
            "1" = "1. Unfinished and finished primary school [Primary]",
            "2" = "2. Three-year secondary school [Primary]",
            "3" = "3. Four-year secondary school [Primary]",
            "4" = "4. University / Undergraduate [College]",
            "5" = "5. Master’s or doctoral degree [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            pol == 1 ~ 0,
            pol == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            tip == 1 ~ 1,
            tip == 2 ~ 0),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: B1 [VB1.7]; QTEXT: Please imagine a scale with values ranging from 1 to 10, where 1 stands for people who you trust least, and 10 for people who you trust most. Where on this scale would you put the following people? People of other religions.; ROPTIONS: 1(2/3/4/5) = Trust least [=1] + (6/7/8/9)10 = Trust most [=0]; TARGET: Different religion; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(VB1.7),
            "88" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            VB1.7 %in% c(1:5) ~ 1,
            VB1.7 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: B10.2 [VB10.2]; QTEXT: How often do you pray?; ROPTIONS: 1 = Very often + 2 = Often + 3 = Rarely + 4 = Very rarely/never",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(VB10.2),
            `88` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (4 - resp_religiosity_original)/3
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Tajikistan

```{r}
# clean tajikistan
  clean_tajikistan <-
    tajikistan_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Tajikistan",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = NA,
    
        resp_interview_start_date = as.Date("2015-02-01"),
        resp_interview_end_date = as.Date("2015-02-12"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            q23 == 1 ~ "Muslim",
            q23 %in% c(2, 3) ~ "Christian",
            q23 %in% c(5, 97, 99) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(q23),
            "1" = "Muslim",
            "2" = "Orthodox",
            "3" = "Catholic",
            "5" = NA_character_,
            "97" = NA_character_,
            "99" = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(d2),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(d4),
            "1" = "1. Elementary [Primary]",
            "2" = "2. Incomplete high school [Primary]",
            "3" = "3. Secondary [Primary]",
            "4" = "4. Vocational [Primary]",
            "5" = "5. Incomplete higher education [Primary]",
            "6" = "6. Complete higher education [College]",
            "7" = "7. Advanced education/scientific degress (doctorate) [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            d1 == 1 ~ 0,
            d1 == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            Village %in% c(10:100) ~ 1,
            City %in% c(1:11) ~ 0),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: 14 [q14.6]; QTEXT: Please tell me to what extent you trust the following people. Imagine a scale from 1 to 10, where 1 means you don't trust them completely, 10 means you trust them completely. People of other religions.; ROPTIONS: 1(2/3/4/5) = Don't trust completely [=1] + (6/7/8/9)10 = Trust completely [=0]; TARGET: Different religion; TYPE: Trust",
    
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(q14.6),
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            q14.6 %in% c(1:5) ~ 1,
            q14.6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: Q22; QTEXT: What is your attitude toward religion?; ROPTIONS: 1 = I am a believer, I am a member of a community and regularly visit a temple and a mosque, I observe rituals, prescriptions and prohibitions, I promote the values of my religion + 2 = I am a believer, but I practically do not participate in religious life, I limit myself to celebrations and some vital ceremonies + 3 = I am not a believer, but I take part in some ceremonies and holidays according to the tradition of my nationality, and I advocate my religion + 4 = I am not a believer, I do not participate in religious life, but I respect the religious feelings of believers and do not hinder them + 5 = I have my own individual belief in various values (e.g., civil religion, personal reverence for moral values, belief in a non-traditional god, etc.) + 6 = I am a non-believer, atheist, and an opponent of religion, I believe that religion does more harm to humanity than good and people need to do away with it",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(q22),
            `7` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (6 - resp_religiosity_original)/5
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Ukraine

```{r}
# clean ukraine
  clean_ukraine <-
    ukraine_raw %>%
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Ukraine",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = as.Date(Date, "%Y-%m-%d"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            Q20 %in% c(1, 3, 4, 10) ~ "Christian",
            Q20 == 2 ~ "Muslim",
            Q20 == 5 ~ "Jewish",
            Q20 == 6 ~ "Other religion",
            Q20 %in% c(98, 99) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(Q20),
            "0" = NA_character_,
            "1" = "Orthodox (Russian/Greek/etc.) ",
            "2" = "Muslim",
            "3" = "Roman Catholic",
            "4" = "Protestant",
            "5" = "Jew",
            "6" = "Other",
            "10" = "Other: Greek Catholic Church",
            "98" = NA_character_,
            "99" = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(Q98),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(Q58),
            "1" = "1. No formal education / incompleted primary school [No education]",
            "2" = "2. Primary school [Primary]",
            "3" = "3. Vocational or technical secondary school [Primary]",
            "4" = "4. Secondary school: university-preparatory type [Primary]",
            "5" = "5. University-level education: Bachelor degree or similar [College]",
            "6" = "6. University-level education: Higher than bachelor degree (MA/MSC degree) [College]",
            "7" = "7. Doctoral or post-doctoral degree [College]",
            "98" = NA_character_,
            "99" = NA_character_,
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            Sex == 1 ~ 1,
            Sex == 2 ~ 0),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            Q99 %in% c(1:2) ~ 1,
            Q99 %in% c(3:4) ~ 0,
            Q99 %in% c(98:99) ~ NA_real_),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: Q17 [Q17.7]; QTEXT: To what degree do you trust the following people? Imagine a scale from 1 to 5, where 1 means no trust at all and 5 very much. People of other religions.; ROPTIONS: 1(2) = No trust at all [=1] + (3/4)5 = Very much trust [=0]; TARGET: Different religion; TYPE: Trust",
      
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(Q17.7),
            "98" = NA_character_,
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            Q17.7 %in% c(1:2) ~ 1,
            Q17.7 %in% c(3:5) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: Q21; QTEXT: How important is God in your life? Please use this scale to indicate. 10 means 'very important' and 1 means 'not at all important.'; ROPTIONS: 1 = Not at all important + (2/3/4/5/6/7/8/9) + 10 = very important",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(Q21),
            `98` = NA_real_,
            `99` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (resp_religiosity_original - 1)/9
    
    ) %>% 
    select(starts_with("resp_"))
```

# Clean Uzbekistan

```{r}
# clean uzbekistan
  clean_uzbekistan <-
    uzbekistan_raw %>%
    rename(rural_urban_temp = 4) %>% # resolves russian character issue
    mutate(
      
    #########################  
    ####### META-DATA #######  
    #########################      
      
      # source name (character vector, title case)
        resp_source = "Friedrich-Ebert-Stiftung Youth Studies in East Europe and Central Asia",
        
      # round number (character vector, title case)  
        resp_round = "",
      
      # url to dataset source, where publicly available (character vector)
        resp_original_data_url = "bit.ly/3LZunlb",

      # survey mode (in-person/phone/internet)
        resp_survey_mode = "in-person",    

      # country (character vector; list of countries as written in original source)
        resp_country_original = "Uzbekistan",

      # country (character vector; converts to countrycode county.name list)
        resp_country_common = 
          countryname(resp_country_original),
        
      # interview date (variable of class Date; if only month given, input 1st of month)
        resp_interview_date = NA,
    
        resp_interview_start_date = as.Date("2015-02-01"),
        resp_interview_end_date = as.Date("2015-02-12"),
   
    #########################  
    ##### DEMOGRAPHICS ######  
    #########################
      
      # respondent's religion (character vector that corresponds to master list)
        resp_religion = 
          case_when(
            q23 == 1 ~ "Muslim",
            q23 %in% c(2, 3) ~ "Christian",
            q23 == 4 ~ "Buddhist",
            q23 %in% c(5, 7, 99) ~ NA_character_),      

      # respondent's religion (character vector that corresponds to master list)
        resp_denomination =
          dplyr::recode(
            as.character(q23),
            "1" = "Muslim",
            "2" = "Orthodox",
            "3" = "Catholic",
            "4" = "Buddhist",
            "5" = NA_character_,
            "7" = NA_character_,
            "99" = NA_character_),   
    
      # respondent's age (character vector; bins denoted by single dash ["18-25"])
        resp_age = as.character(D2.1),        
      
      # respondent's education level
        resp_education_original =
          dplyr::recode(
            as.character(D4),
            "1" = "1. Elementary [Primary]",
            "2" = "2. Incomplete high school [Primary]",
            "3" = "3. Secondary [Primary]",
            "4" = "4. Vocational [Primary]",
            "5" = "5. Incomplete higher education [Primary]",
            "6" = "6. Complete higher education [College]",
            "7" = "7. Advanced education/scientific degress (doctorate) [College]",
            .default = NA_character_),       
      
      # respondent's gender (numeric: female = 1; male = 0; other = NA)
        resp_female = 
          case_when(
            D1 == 1 ~ 0,
            D1 == 2 ~ 1),
      
      # respondent resident in rural (vs urban) area (numeric: rural = 1; urban/semi-urban/peri-urban = 0)
        resp_rural =
          case_when(
            rural_urban_temp %in% c(200:1600) ~ 1,
            city %in% c(10:150) ~ 0),
      
    #########################  
    ### SOCIAL DISTANCE 1 ###  
    #########################
    
      # original question number; question text; response options (input above)
        resp_soc_dist_1_qinfo = "NUM: 14 [q14.6]; QTEXT: Please tell me to what extent you trust the following people. Imagine a scale from 1 to 10, where 1 means you don't trust them completely, 10 means you trust them completely. People of other religions.; ROPTIONS: 1(2/3/4/5) = Don't trust completely [=1] + (6/7/8/9)10 = Trust completely [=0]; TARGET: Different religion; TYPE: Trust",
    
      # original response (as character vector)
        resp_soc_dist_1_original = 
          dplyr::recode(
            as.character(q14.6),
            "99" = NA_character_),       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_soc_dist_1_bin_recode = 
          case_when(
            q14.6 %in% c(1:5) ~ 1,
            q14.6 %in% c(6:10) ~ 0,
            TRUE ~ NA_real_),
    
    ############################  
    ### GENERAL SOCIAL TRUST ###  
    ############################
    
      # original question number; question text; response options (input above)
        resp_gentrust_qinfo = NA, # checked; no general trust question

      # original response (as character vector)
        resp_gentrust_original = NA,       

      # binary recode (numeric: 1 = any negative attitude expressed; 0 otherwise)
        resp_gentrust_bin_recode = NA,    
    
    #########################  
    ##### RELIGIOSITY #######
    #########################
    
      # original question number; question text; response options (input above)
        resp_religiosity_qinfo = "NUM: Q22; QTEXT: What is your attitude toward religion?; ROPTIONS: 1 = I am a believer, I am a member of a community and regularly visit a temple and a mosque, I observe rituals, prescriptions and prohibitions, I promote the values of my religion + 2 = I am a believer, but I practically do not participate in religious life, I limit myself to celebrations and some vital ceremonies + 3 = I am not a believer, but I take part in some ceremonies and holidays according to the tradition of my nationality, and I advocate my religion + 4 = I am not a believer, I do not participate in religious life, but I respect the religious feelings of believers and do not hinder them + 5 = I have my own individual belief in various values (e.g., civil religion, personal reverence for moral values, belief in a non-traditional god, etc.) + 6 = I am a non-believer, atheist, and an opponent of religion, I believe that religion does more harm to humanity than good and people need to do away with it",
  
      # original response (as numeric vector, with non-substantive responses coded as NA_real_)
        resp_religiosity_original = 
          dplyr::recode(
            as.numeric(q22),
            `7` = NA_real_),       

      # recode (numeric: scaled 0-1, where 1 is more religious)
        resp_religiosity_recode = (6 - resp_religiosity_original)/5
    
    ) %>% 
    select(starts_with("resp_"))
```

# Stack

```{r}
  stacked <-
    clean_bulgaria %>%
    bind_rows(clean_kosovo) %>%
    bind_rows(clean_romania) %>%
    bind_rows(clean_slovenia) %>%
    bind_rows(clean_serbia) %>%
    bind_rows(clean_ukraine) %>%
    bind_rows(clean_kazakhstan) %>%
    bind_rows(clean_kyrgyzstan) %>%
    bind_rows(clean_tajikistan) %>%
    bind_rows(clean_uzbekistan)
```

# Save

```{r}
  saveRDS(stacked, "../cleaned-data/y-20-fes-youth-studies-east-europe-central-asia.rds")
```